# NA与NULL的区别
a <- NA
b <- c(1, 2, 3, NA)

c <- NULL
d <- c(1, 2, 3, NULL)

sum(b)
sum(d)

e <- 5

a + e
c + e

# ------------------------------------------
# 准备工作
# ------------------------------------------

setwd("/Users/eimei/Documents/Rdata/")  # 设定工作空间
data <- read.csv("HRdata.csv")  # 读取数据

newdata <- data[c("EmployeeNumber", "Age", "Department",
                  "EnvironmentSatisfaction", "JobSatisfaction",
                  "MonthlyIncome", "RelationshipSatisfaction")]

head(newdata)

# ------------------------------------------
# 任务一
# ------------------------------------------
temp <- newdata[1:10, ]

temp$MonthlyIncome[temp$EmployeeNumber >= 7 & temp$EmployeeNumber <= 10] <- NA
temp$MonthlyIncome[temp$EmployeeNumber == 13] <- NA

temp

# ------------------------------------------
# 任务二
# ------------------------------------------

mean(temp$MonthlyIncome)
mean(temp$MonthlyIncome, na.rm = TRUE)


# ------------------------------------------
# 任务三
# ------------------------------------------
temp1 <- na.omit(temp)
temp1